package com.idp.biz.bpusermessage.service.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.common.model.PageModel;
import com.common.utils.ResourceUtil;
import com.idp.biz.bpusermessage.service.BpUserMessageService;
import com.idp.biz.bpusermessage.dao.BpUserMessageDao;
import com.idp.biz.bpusermessage.entity.BpUserMessage;

/**
 * 用户消息service实现类
 * 
 * @author Stone 2019-06-29
 *
 */
@Service("bpUserMessageService")
public class BpUserMessageServiceImpl implements BpUserMessageService {

	@Autowired
	private BpUserMessageDao bpUserMessageDao;
	
	@Override
	public PageModel<BpUserMessage> findByPage(BpUserMessage bpUserMessage, PageModel<BpUserMessage> page) {
		PageHelper.offsetPage(page.getStart(), page.getLength());
		page.initData(bpUserMessageDao.findByPage(bpUserMessage));
		return page;
	}
	
	@Override
	public List<BpUserMessage> findBySearch(BpUserMessage bpUserMessage) {
		return bpUserMessageDao.find(bpUserMessage);
	}
	
	@Override
	public BpUserMessage getById(String id) {
		return bpUserMessageDao.getById(id);
	}

	@Override
	public void add(BpUserMessage bpUserMessage) {
		bpUserMessage.setId(ResourceUtil.getUUID());
		bpUserMessageDao.add(bpUserMessage);
	}
	
	@Override
	public void update(BpUserMessage bpUserMessage) {
//		bpUserMessageDao.update(bpUserMessage);
		bpUserMessageDao.updateNotNull(bpUserMessage);
	}

	@Override
	public void delete(String ids) {
		List<String> idList = Arrays.asList(ids.split(","));
		bpUserMessageDao.batchDelete(idList);
	}
 	
}